﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Adex;
using MediaMonitor.Common;
using Telerik.Web.UI;


namespace MediaMonitor.Admin
{
    public partial class Data_Mgmt_Traffic : System.Web.UI.Page
    {
        //DateTime sDate = DateTime.MinValue, eDate = DateTime.MinValue;
        protected void Page_Load(object sender, EventArgs e)
        {
            //Utility.AddDateControlToPage(this.Page);
           
        }
     

        protected void radGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            DataTable dt = Adex.TblTrafficLog.Query().DISTINCT().SetSelectList("DateAdded").ORDER_BY("DateAdded").ExecuteDataSet().Tables[0];

            DataTable cloneDataTable = dt.Clone();

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < 1; i++)
                {
                    cloneDataTable.ImportRow(dt.Rows[i]);
                }
            }
            radGrid.DataSource = cloneDataTable;
          
        }

        protected void radGrid_DeleteCommand(Object source, Telerik.Web.UI.GridCommandEventArgs e)
        {

            //check deletion of child rows
            if (e.Item.OwnerTableView.DataSourceID == "sqlDSTraffic")
            {
                string detailPkId = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["TrafficLogID"].ToString();
                try
                {
                    TblTrafficLog.Delete(detailPkId);
                }
                catch
                {
                    AjaxFuncs.MsgBox(this, "Failed to delete this record, because related data (child records) exists in other tables");
                }

                return;
            }



           

            try
            {
                RfController.DeleteAllPlanning();
               
            }
            catch
            {
                AjaxFuncs.MsgBox(this, "Failed to delete this record, because related data (child records) exists in other tables");
            }

            radGrid.Rebind();
        }

        

    }
}